//
//  Display.m
//  We365
//
//  Created by Bui Thien An on 12/29/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Display.h"
#import "Utilities.h"

@implementation Display

static NSMutableDictionary *allDisplay;

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

+ (BOOL)checkExists
{
    return [Utilities checkExists:DisplayName];
}

+ (NSMutableDictionary *)getAllDisplay
{
    return allDisplay;
}

+ (void)loadDisplay
{
    if (![self checkExists]) {
        [self defaultDisplay];
    }
    else {
        allDisplay = [[NSMutableDictionary dictionaryWithContentsOfFile:[self displayFilePath]] copy];
    }
}

+ (NSString *)displayFilePath
{
    return [Utilities getFilePath:DisplayName];
}

+ (void)saveDisplay
{
    [allDisplay writeToFile:[self displayFilePath] atomically:YES];
}

+ (void)defaultDisplay
{
    NSArray *tempArr = [NSArray arrayWithObjects:@"Button 1",@"Button 2",@"Button 3",@"Button 4",@"Button 5",@"Button 6",@"Button 7",@"Button 8", nil];
    NSMutableDictionary *temp = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1",@"0",@"0",@"0",@"0",@"0",@"0",@"0",nil] forKeys:[NSArray arrayWithArray:tempArr]];
    
    allDisplay = [NSMutableDictionary dictionaryWithDictionary:temp];
    [self saveDisplay];
}

+ (void)updateDisplay:(NSString *)key andValue:(NSString *)value
{
    //[allDisplay setObject:value forKey:key];
    NSMutableDictionary *mulTemp = [[NSMutableDictionary alloc] initWithDictionary:allDisplay];
    //NSArray *temp = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%@",value], nil];
    //[self getAllDisplay];
    [mulTemp setObject:value forKey:key];
    //[mulTemp writeT atomically:<#(BOOL)#>
    [mulTemp writeToFile:[self displayFilePath] atomically:YES];
    //[temp release];
    [mulTemp release];
    //[self saveDisplay];
}
@end
